import numpy as np
from plyfile import PlyData,PlyElement
from numba import jit
import open3d as o3d
from time import time
@jit
def cc(points):
    points = [(points[i, 0], points[i, 1], points[i, 2]) for i in range(points.shape[0])]
    vertex = np.array(points, dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
    return vertex
def write_ply(save_path,points,text=True):
    """
    save_path : path to save: '/yy/XX.ply'
    pt: point_cloud: size (N,3)
    """
    # points = [(points[i,0], points[i,1], points[i,2]) for i in range(points.shape[0])]
    # vertex = np.array(points, dtype=[('x', 'f4'), ('y', 'f4'),('z', 'f4')])
    el = PlyElement.describe(points, 'vertex', comments=['vertices'])
    PlyData([el], text=text).write(save_path)

if __name__=='__main__':
    t1=time()
    res = np.loadtxt('/home/wsl/zz/txt/replay_99587_2021-9-24.txt', delimiter=',')
    t2=time()
    print(t2-t1)
    pcd = o3d.geometry.PointCloud()
    pcd.points = o3d.utility.Vector3dVector(res)
    o3d.io.write_point_cloud("/home/wsl/zz/replay_99587_2021-9-24.ply", pcd)
    #res=cc(res)
    #write_ply('/home/wsl/zz/replay_93936_2021-9-22.ply',res)